package com.chidopi.member.actions;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.commons.beanutils.DynaBean;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.chidopi.cdf.struts1actions.CdfDispatchAction;
import com.chidopi.cdf.util.ModelContextFactory;
import com.chidopi.member.domain.Member2City;
import com.chidopi.member.service.IMemberMaintainService;

public class MemberAction extends CdfDispatchAction {
	private static Logger logger = LoggerFactory.getLogger(MemberAction.class);
	private IMemberMaintainService memMainService;
	
	public MemberAction() {
		try {
			this.memMainService = ModelContextFactory.getT("memberMaintainService", IMemberMaintainService.class);
		} catch (Exception e) {
			logger.warn("init", e);
		}
	}
	
	public ActionForward init(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String username = (String) request.getSession().getAttribute("username");
		List<Member2City> list = this.memMainService.findMember2City(username);
		JSONArray ary = JSONArray.fromObject(list);
		DynaBean dynaForm = (DynaBean) form;
		dynaForm.set("members", ary.toString());
		return mapping.findForward("success");
	}
	
	public ActionForward ajaxMember2CityQuery(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return null;
	}
}
